package com.huilian.iotbox.client.controller;

import com.huilian.iotbox.client.security.jwt.util.JwtTokenUtil;
import com.huilian.iotbox.client.service.MerchantStoreService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.MemberDto;
import com.huilian.iotbox.data.dto.MerchantStoreDeviceDto;
import com.huilian.iotbox.data.dto.MerchantStoreDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 谢洛涛
 * @date 2021/1/18 18:06
 */
@RestController
@RequestMapping("/api/merchantStore")
public class MerchantStoreController extends BaseController {
    @Autowired
    private MerchantStoreService merchantStoreService;

    @Autowired
    private JwtTokenUtil jwtTokenUtil;


    @GetMapping("/findMerchantStoreById")
    public ServerResponse findMerchantStoreById(HttpServletRequest request, MerchantStoreDto merchantStoreDto) throws Exception {
        return ServerResponse.createBySuccess(merchantStoreService.findMerchantStore(merchantStoreDto));
    }

    /**
     * 最近场地列表
     */
    @PostMapping("/findRecentlyMerchantStoreByMember")
    public ServerResponse findRecentlyMerchantStoreByMember(@RequestBody MerchantStoreDto merchantStoreDto, HttpServletRequest request) throws Exception {
        final MemberDto member = jwtTokenUtil.getMemberFromReq(request);
        merchantStoreDto.setMemberId(member.getId());
        return merchantStoreService.findRecentlyMerchantStoreByMember(merchantStoreDto);
    }

}
